/**
 * 
 */
package org.dailydev.mojo.birt.runner;

import org.apache.maven.plugin.MojoExecutionException;

/**
 * @author bosakrom
 * 
 */
public class FormatEnum {

	private static final String HTML_VALUE = "html";
	private static final String PDF_VALUE = "pdf";
	private static final String PPT_VALUE = "ppt";
	private static final String DOC_VALUE = "doc";
	private static final String POSTSCRIPT_VALUE = "postscript";
	private static final String XLS_VALUE = "xls";

	public static final FormatEnum HTML = new FormatEnum(HTML_VALUE);
	public static final FormatEnum PDF = new FormatEnum(PDF_VALUE);
	public static final FormatEnum PPT = new FormatEnum(PPT_VALUE);
	public static final FormatEnum DOC = new FormatEnum(DOC_VALUE);
	public static final FormatEnum POSTSCRIPT = new FormatEnum(POSTSCRIPT_VALUE);
	public static final FormatEnum XLS = new FormatEnum(XLS_VALUE);

	/**
	 * @param value
	 * @return
	 * @throws MojoExecutionException
	 */
	public static FormatEnum fromValue(String value) throws MojoExecutionException {
		if (value == null) {
			throw new NullPointerException("Value can not be null");
		}
		FormatEnum[] literal = values();
		for (int i = 0; i < literal.length; i++) {
			if (literal[i].getValue().equalsIgnoreCase(value)) {
				return literal[i];
			}
		}
		throw new MojoExecutionException("Unsupported format '" + value + "'. Supported values are: "
				+ FormatEnum.values());
	}

	/** {@inheritDoc} */
	public static FormatEnum[] values() {
		return new FormatEnum[] { HTML, PDF, PPT, DOC, POSTSCRIPT, XLS };
	}

	private final String value;

	/**
	 */
	private FormatEnum(String value) {
		this.value = value;
	}

	/**
	 * Returns literal value
	 * 
	 * @return literal value
	 */
	public String getValue() {
		return this.value;
	}

	/** {@inheritDoc} */
	public String toString() {
		return this.getValue();
	}
}
